package com.clpms.utils;

import com.clpms.bean.enumBean.ErrorCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 结果的包装
 *
 * @author caixinyong
 * @date 2023/1/24 6:36 PM
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResultDto<T> {
	private Integer code;
	private String msg;
	private T data;

	public static String PARAM_ERROR = "参数不合法";

	public static ResultDto Success() {
		return Success(null);
	}

	public static ResultDto Success(Object data) {
		return ResultDto.builder().code(200).msg("请求成功").data(data).build();
	}

	public static ResultDto Fail(Integer code, String msg) {
		return Fail(code, msg, null);
	}

	public static ResultDto Fail(Integer code, String msg, Object data) {
		return ResultDto.builder().code(code).msg(msg).data(data).build();
	}

	public static ResultDto Fail(ErrorCodeEnum errorCode) {
		return ResultDto.builder().code(errorCode.getCode()).msg(errorCode.getMsg()).build();
	}

	public static ResultDto Fail(ErrorCodeEnum errorCode, Object data) {
		return ResultDto.builder().code(errorCode.getCode()).msg(errorCode.getMsg()).data(data).build();
	}
}
